function validateLogin(form) {
	var username = form.username.value;
	var password = form.password.value;
	
	if(username == "") {
		alert("Niste upisali korisničko ime!");
		return false;
	}
	if(password == "") {
		alert("Niste upisali lozinku!");
		return false;
	}
	return true;
}


function potvrdiBrisanjeKorisnika(id, name) {
	var answer = confirm("Jeste li sigurni da zelite pobrisati korisnika " + name + "?");
	if (answer){
		window.location = "exec/korisnici.php?action=delete&id=" + id;
	}
	else{
		window.location = "index.php?action=admin/korisnici";
	}
}

var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	if(divError) divError.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 

function fillOption(select, editId) {
	
	var option = String(select.options[select.selectedIndex].value);
	edit = document.getElementById(editId);
	if (option.length == 0) return;
	
	var tmp = edit.getAttribute("value");
		
	if (tmp == null || tmp.length == 0) edit.setAttribute("value", option);
	else edit.setAttribute("value", tmp + "; " + option);
}

function removeOption(editId) {
	edit = document.getElementById(editId);

	tmp = String(edit.getAttribute("value"));
	var pos =0;
	var i=0;
	for (i=tmp.length-2; i>=0; i--) {
		if (tmp.charAt(i) == ";") {
			pos = i;
			break;
		}
	}
	tmp = tmp.substring(0, pos);
	edit.setAttribute("value", tmp);
}

function fillOptionWithInput(editId) {
	var option = prompt("Upišite sinonim: ");
	edit = document.getElementById(editId);
	if (option.length == 0) return;
	
	var tmp = edit.getAttribute("value");
		
	if (tmp == null || tmp.length == 0) edit.setAttribute("value", option);
	else edit.setAttribute("value", tmp + "; " + option);
}
